package com.devilvan.betrice.opgg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.opgg.dto.OpggChampionRoleDto;
import com.devilvan.betrice.opgg.po.OpggChampionRolePo;
import com.devilvan.betrice.opgg.service.OpggChampionRoleService;
import com.devilvan.betrice.opgg.mapper.OpggChampionRoleMapper;
import com.devilvan.betrice.opgg.repository.OpggChampionRoleRepository;
import org.springframework.stereotype.Service;
import com.devilvan.betrice.util.UCopy;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Evad.Wu
 * @Description OPGG-英雄角色定位信息 业务逻辑类
 * @date 2022-10-04
 */
@Service
public class OpggChampionRoleServiceImpl extends ServiceImpl<OpggChampionRoleMapper, OpggChampionRolePo> implements OpggChampionRoleService {
    @Resource(name = "opggChampionRoleRepository")
    private OpggChampionRoleRepository opggChampionRoleRepository;

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public OpggChampionRolePo saveUpdate(OpggChampionRoleDto opggChampionRoleDto) {
        OpggChampionRolePo opggChampionRolePo = new OpggChampionRolePo();
        UCopy.fullCopy(opggChampionRoleDto, opggChampionRolePo);
        return opggChampionRoleRepository.saveAndFlush(opggChampionRolePo);
    }

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public List<OpggChampionRolePo> saveUpdateBatch(List<OpggChampionRoleDto> list) {
        List<OpggChampionRolePo> opggChampionRolePoList = UCopy.fullCopyCollections(list, OpggChampionRolePo.class);
        return opggChampionRoleRepository.saveAllAndFlush(opggChampionRolePoList);
    }
}
